n=int(input())
arr=[]
brr=[]
for _ in range(n):
a,b=map(int,input().split())
arr.append(a)
brr.append(b)
for i in range(n):
if (arr[i] in brr[:i] or arr[i] in brr[i+1:]):
n-=1
else:
continue
print(n)
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <array>
#include <any>
using namespace std;
#ifdef LOCAL
#define eprintf(...) \
{ \
fprintf(stderr, __VA_ARGS__); \
fflush(stderr); \
}
#else
#define eprintf(...) 42
#endif
using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template <typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
int MOD = 1e9 + 7;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B)
{
return (ull)rng() % B;
}
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define fi first
#define se second
#define print(...) cout << ... << endl;
#define nl "\n"
#define REPL(x, n) for(int x = 0; x < n; ++x)
clock_t startTime;
double getCurrentTime() {
return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}
void printiv(vector<ll> v) {
for (int ele : v) {
cout << ele << " ";
}
cout << endl;
}
pair<int,int> arr[1001] {mp(-1, -1)};
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n;
int a, b;
cin >> n;
unordered_set<int> needstobeopened = {};
REPL(i, n) {
cin >> a >> b;
arr[i] = mp(a, b);
needstobeopened.insert(i);
}
unordered_set<int> hasbeenopened = {};
stack<int> isopenedoniter = {};
int cnt = 0;
REPL(i, n) {
b = arr[i].second;
REPL(j, n) {
if(i == j) continue;
if (arr[j].first == b && (hasbeenopened.count(b) == 0 || needstobeopened.count(j) > 0)) {
//cout << b << nl;
cnt += 1;
needstobeopened.erase(j);
isopenedoniter.push(b);
}
}
while(!isopenedoniter.empty()) {
int tmp;
tmp = isopenedoniter.top();
isopenedoniter.pop();
hasbeenopened.insert(tmp);
}
}
cout << n - cnt << nl;
return 0;
}
1647D - Madoka and the Best School in Russia | 1208A - XORinacci |
1539B - Love Song | 22B - Bargaining Table |
1490B - Balanced Remainders | 264A - Escape from Stones |
1506A - Strange Table | 456A - Laptops |
855B - Marvolo Gaunt's Ring | 1454A - Special Permutation |
1359A - Berland Poker | 459A - Pashmak and Garden |
1327B - Princesses and Princes | 1450F - The Struggling Contestant |
1399B - Gifts Fixing | 1138A - Sushi for Two |
982C - Cut 'em all | 931A - Friends Meeting |
1594A - Consecutive Sum Riddle | 1466A - Bovine Dilemma |
454A - Little Pony and Crystal Mine | 2A - Winner |
1622B - Berland Music | 1139B - Chocolates |
1371A - Magical Sticks | 1253A - Single Push |
706B - Interesting drink | 1265A - Beautiful String |
214A - System of Equations | 287A - IQ Test |